package com.briup.cms.web.controller;



import com.briup.cms.bean.User;

import com.briup.cms.service.IUserService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(description = "用户管理接口")
@RequestMapping("/user")
@RestController
public class UserController {
    @Autowired
    private IUserService userService;

    @ApiOperation(value = "查询所有")
    @GetMapping("findAll")
    public Message findAll(){
        List<User>  list= userService.findAll();
        return MessageUtil.success(list);
    }
    @ApiOperation(value = "保存或更新")
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(User user){
      userService.saveOrUpdate(user);
        return MessageUtil.success("操作成功");
    }
    @ApiOperation(value="删除")
    @GetMapping("deleteById")
    public Message deleteById(long id){
        userService.deleteById(id);
        return MessageUtil.success("操作成功");
    }



    @PostMapping("login")
    public Message login(String username, String password) {
        Map<String, String> map = new HashMap<>();
        map.put("token", "admintoken");
        return MessageUtil.success(map); }

        @GetMapping("info")
        public Message info() {
            User user = new User();
            user.setRealName("超级管理员");
            user.setPhoto("http://121.199.29.84:8888/group1/M00/00/05/rBD-SV7-iN6Abe0NAAAXCfK1yz8375.jpg");
            return MessageUtil.success(user);
        }

        @PostMapping("logout")
        public Message logout () {
            return MessageUtil.success("退出成功");
        }
    }

